package com.android.djlmapp.adapter.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

import com.android.djlmapp.R;
import com.android.djlmapp.model.kaika.SelectTcInfo;

import java.util.List;

public class SxAdapter extends BaseAdapter {
    private Context mContext;
    private Activity mActivity;
    int selectedIndex = -1;
    private List<SelectTcInfo.SpecList.Sys.Type> mList;

    public SxAdapter(Context context, List<SelectTcInfo.SpecList.Sys.Type> list) {
        this.mContext = context;
        this.mActivity = (Activity) context;
        this.mList = list;
    }

    public void setSelectedIndex(int index) {
        selectedIndex = index;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public SelectTcInfo.SpecList.Sys.Type getItem(int position) {
        SelectTcInfo.SpecList.Sys.Type typeInfo = mList.get(position);
        return typeInfo;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = View.inflate(mActivity, R.layout.item_time, null);
        CheckBox tc_name = view.findViewById(R.id.tc_name);
        tc_name.setText(mList.get(position).getMsg());

        if (selectedIndex == position) {

            tc_name.setChecked(true);
        } else {
            tc_name.setChecked(false);
        }

        return view;
    }
}